/*
 * DTOAsteroide.cpp
 *
 *  Created on: Apr 1, 2012
 *      Author: gonzalo
 */

#include "DTOAsteroide.h"
#include "utils/InstanceDuplicater.h"


DTOAsteroide::DTOAsteroide(const DTOAsteroide& other) : DTO(other){
	this->Id = other.Id;
	this->x = other.x;
	this->y = other.y;
	this->direccion = other.direccion;
	this->velocidad = other.velocidad;
	this->nivel = other.nivel;
	this->drawable = other.drawable;
	this->slimDTOVersion = other.slimDTOVersion;

	this->tipo = (DTOTipoAsteroide*)InstanceDuplicater::duplicate(other.tipo);
}
DTOAsteroide::DTOAsteroide(int Id, int nivel,DTOTipoAsteroide* tipo,int x,int y,int direccion,int velocidad, bool drawable , std::string owner, bool slimDTOVersion)
:DTO(ASTEROIDE_STATUS,owner){
	this->Id = Id;

	this->tipo = tipo;
	this->tipo->slimDTOVersion = slimDTOVersion;

	this->x = x;
	this->y = y;
	this->direccion = direccion;
	this->velocidad = velocidad;
	this->nivel = nivel;
	this->drawable = drawable;
	this->slimDTOVersion = slimDTOVersion;
}


DTOAsteroide::DTOAsteroide(std::string& aDeserealizar, std::string owner) :
		DTO(ASTEROIDE_STATUS, owner) {
	deserializar(aDeserealizar, owner);
}

std::string DTOAsteroide::serializar(){
	std::stringstream retorno;

	retorno << UtilString::TOlenghtStringStringValue(Id);
	retorno << UtilString::TOlenghtStringStringValue(nivel);
	retorno << UtilString::TOlenghtStringStringValue(x);
	retorno << UtilString::TOlenghtStringStringValue(y);
	retorno << UtilString::TOlenghtStringStringValue(direccion);
	retorno << UtilString::TOlenghtStringStringValue(velocidad);
	retorno << UtilString::TOlenghtStringStringValue(drawable);
	retorno << UtilString::TOlenghtStringStringValue(slimDTOVersion);

	if(!slimDTOVersion)
		retorno << tipo->serializar();


	return retorno.str();
}
void DTOAsteroide::deserializar(std::string& string,std::string owner){
	Id = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	nivel = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	x = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	y = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	direccion = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	velocidad = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	drawable = UtilString::stringToBool(UtilString::FROMlenghtStringStringValue(string));
	slimDTOVersion = UtilString::stringToBool(UtilString::FROMlenghtStringStringValue(string));

	tipo = (!slimDTOVersion) ? new DTOTipoAsteroide(string,owner) : NULL;
}

bool DTOAsteroide::getDrawable(){
	return drawable;
}

DTOAsteroide::~DTOAsteroide(){
	if(tipo) delete tipo;
}
